------------------------------------------
-- NET WORK DATA TABLE
------------------------------------------
CREATE TABLE network
(
    host   character varying(96)  NOT NULL,
    ip     character varying(96)  NOT NULL,
    itime  timestamp without time zone NOT NULL,
    key1   character varying(96)  NOT NULL,
    key2   character varying(192) NOT NULL,
    key3   character varying(192) NOT NULL,
    value  double precision       NOT NULL,
    size   smallint DEFAULT 0
) PARTITION BY RANGE (itime) INTERVAL('30 minutes') (
    PARTITION sys_p443 VALUES LESS THAN ('2000-01-01 00:00:00') TABLESPACE pg_default
)
ENABLE ROW MOVEMENT;


CREATE INDEX network_index2 
ON network 
USING btree (itime) 
LOCAL(PARTITION sys_p443_itime_idx)
TABLESPACE pg_default;

CREATE UNIQUE INDEX network_unique
ON network
USING btree (ip, key1, key2, key3, itime, value)
LOCAL(PARTITION sys_p443_ip_key1_key2_key3_itime_v_idx)
TABLESPACE pg_default;

------------------------------------------
-- NET WORK DATA HUGE TABLE
------------------------------------------
CREATE TABLE network_huge (
    ip    character varying(64) NOT NULL,
    itime timestamp without time zone NOT NULL,
    key1  character varying(64) NOT NULL,
    key2  character varying(128) NOT NULL,
    key3  character varying(128) NOT NULL,
    value double precision NOT NULL,
    itime_minute timestamp without time zone GENERATED ALWAYS AS (
        date_trunc('hour'::text, itime) +
        ((((date_part('minute'::text, itime) / (10)::double precision) +
        (.5)::double precision):: integer)::double precision *
        '00:10:00'::interval)) STORED,
    itime_month timestamp without time zone GENERATED ALWAYS AS (
        date_trunc('day'::text, itime)) STORED
) PARTITION BY RANGE (itime) INTERVAL('30 minutes') (
    PARTITION sys_p345 VALUES LESS THAN ('2000-01-01 00:00:00') TABLESPACE pg_default
)
ENABLE ROW MOVEMENT;

CREATE INDEX network_huge_index1
ON network_huge
USING btree (ip, key1, key2, key3, value, itime, itime_minute)
TABLESPACE pg_default;


------------------------------------------
-- NET WORK DATA THRECHOLD TABLE
------------------------------------------
CREATE TABLE network_thr (
    ip character varying(96) NOT NULL,
    key1 character varying(96) NOT NULL,
    key2 character varying(192) NOT NULL,
    key3 character varying(192) NOT NULL,
    thresholdrange character varying(256),
    aithreshold character varying(256),
    tolerance double precision DEFAULT 0,
    size_avg smallint DEFAULT 1,
    size_min double precision DEFAULT 0,
    size_max double precision DEFAULT 0,
    is_send smallint DEFAULT 1,
    last_updatetime timestamp without time zone DEFAULT pg_systimestamp(),
    is_send_thr boolean DEFAULT 0
);

ALTER TABLE network_thr 
ADD CONSTRAINT network_thr_primary_key PRIMARY KEY (key1, key3, key2, ip);



